<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
session_start();
class AdminPageController extends CI_Controller {

	function __construct()
	{
		parent::__construct();
		$this->load->helper('url');
	}

	function index()
	{
		if(!isset($_SESSION["session_id"])) $this->load->view('ErrorNotLoggedInView');
		else{
		$this->load->model('Admin_model');
		$data['details'] = $this->Admin_model->get_details('ACCI Dormitory');
		$this->load->view('AdminPageView',$data);}
	}
	
	function loadEditDetailsView()
	{
		if(!isset($_SESSION["session_id"])) $this->load->view('ErrorNotLoggedInView');
		else{
		$this->load->model('Admin_model');
		$data['details'] = $this->Admin_model->get_details('ACCI Dormitory');
		$data['title'] = 'Edit Dormitory Details';
		$data['jsSnippet'] = 'jsSnippets/editDetailsJsSnippet';
		$data['htmlSnippet'] = 'htmlSnippets/editDetailsHtmlSnippet';
		$this->load->view('generic/GenericView',$data);}
	}
	
	function editDetails()
	{
		if(!isset($_SESSION["session_id"])) $this->load->view('ErrorNotLoggedInView');
		else{
		$this->load->model('Admin_model');
		$this->Admin_model->edit_details($_POST);
		redirect('adminPageController/');}
	}
	
	function generateReportTally(){
		if(!isset($_SESSION["session_id"])) $this->load->view('ErrorNotLoggedInView');
		else{
		$this->load->library('cezpdf');
		$pdf = new Cezpdf('A4','landscape');
		$pdf->ezSetCmMargins(2.5,2.5,2.5,2.5);
		
		$header_data[] = array('form' => 'WRH Form');
		$header_data[] = array('form' => 'Series 2004');
		$col_names = array('form'=>'form');
		$pdf->ezTable($header_data,$col_names,'',array('showHeadings'=>0,'rowGap'=>0,'width'=>700,'fontSize'=>7));
		
		$header_data[] = array('info' => 'ACCI RESIDENCE HALL');
		$header_data[] = array('info' => 'STUDENT HOUSING OFFICE');
		$header_data[] = array('info' => 'U.P. at Los Banos');
		$header_data[] = array('info' => 'College, Laguna');
		$header_data[] = array('info' => '');
		$header_data[] = array('info' => 'LIST OF RESIDENTS for 1st Semester 2010-2011');
		$header_data[] = array('info' => '');
		$col_names = array('info'=>'info');
		$pdf->ezTable($header_data,$col_names,'',array('showHeadings'=>0,'rowGap'=>0,'width'=>700,'fontSize'=>7,'cols'=>array('info'=>array('justification'=>'center'))));
		
		$query = $this->db->query("SELECT * FROM resident_basic_info");
		$number=1;
		foreach($query->result_array() as $row){
			$db_data[] = array(
				'number' => $number,
				'student_number' => $row['student_number'],
				'name' => $row['last_name'].' '.$row['first_name'].' '.$row['middle_name'],
				'college' => $row['college'],
				'course' => $row['course'],
				'classification' => $row['classification'],
				'birthday' => $row['birthday'],
				'scholarship' => '',
				'stfap' => '',
				'date_in' => '',
				'form_5' => '',
				'room_number' => '',
				'region' => '',
				'remark' => '',
				);
			$number++;
		}
		$col_names = array(
		'number' => '',
		'student_number' => 'ST Number',
		'name' => 'Name',
		'college' => 'College',
		'course' => 'Course',
		'classification' => 'Class.',
		'birthday' => 'Birthday',
		'scholarship' => 'Scholarship',
		'stfap' => 'STFAP',
		'date_in' => 'Date In',
		'form_5' => 'FORM 5',
		'room_number' => 'Room Number',
		'region' => 'Region',
		'remark' => 'Remarks'
		);
		$pdf->ezTable($db_data, $col_names, '', array('width'=>700,'fontSize'=>7,'titleFontSize'=>13));
		$space="                                       ";
		//footer
		$this->load->model('Admin_model');
		$query = $this->Admin_model->get_details('ACCI Dormitory');
		$row = $query->row();
		
		$pdf->ezText("\n\nPrepared and Submitted by:",10);
		$pdf->ezText("\n\n".$space.$row->manager."",10);
		$pdf->ezText($space.$row->position."",10);
		
		$pdf->ezText("\nNoted by:",10);
		$pdf->ezText("\n\n".$space.$row->name1."",10);
		$pdf->ezText($space.$row->position1."",10);
		$pdf->ezText("\n\n".$space.$row->name2."",10);
		$pdf->ezText($space.$row->position2."",10);

		$pdf->ezStream();}
	}
	
	function generateResidentList(){
		if(!isset($_SESSION["session_id"])) $this->load->view('ErrorNotLoggedInView');
		else{
		$this->load->library('cezpdf');
		$pdf = new Cezpdf('A4','portrait');
		$pdf->ezSetCmMargins(1,2,2,2);
		
		//header
		$pdf->ezText('ACCI RESIDENCE HALL',12,array('justification'=>'center'));
		$pdf->ezText('STUDENT HOUSING OFFICE',12,array('justification'=>'center'));
		$pdf->ezText('Vice Chancellor for Community Affairs',12,array('justification'=>'center'));
		$pdf->ezText('U.P. LOS BANOS',12,array('justification'=>'center'));
		$pdf->ezText('First Semester 2010-2011',12,array('justification'=>'right'));
		$pdf->ezText('RESIDENT\'S PROFILE',12,array('justification'=>'center'));
		$pdf->ezText('',12,array('justification'=>'center'));
		
		$this->load->model('Report_model');
		
		//accomodation table
		$pdf->ezText("I. ACCOMODATION:",12,array('justification'=>'left'));
		$pdf->ezText('',12,array('justification'=>'left'));
		$info_male = $this->Report_model->get_count_accomodation("Male");
		$info_female = $this->Report_model->get_count_accomodation("Female");
		$male=$info_male->row();
		$female=$info_female->row();
		$db_data1[] = array('male'=>$male->accomodation_count,'female'=>$female->accomodation_count,'total'=>$male->accomodation_count+$female->accomodation_count);
		$col_names = array(
			'male' => 'Male',
			'female' => 'Female',
			'total' => 'Total'
		);
		$pdf->ezTable($db_data1, $col_names, '', array('width'=>200,'fontSize'=>12,'titleFontSize'=>13,'xPos'=>'left','xOrientation'=>'right'));
		$pdf->ezText('',12,array('justification'=>'left'));
		
		//vacancy table
		$pdf->ezText("II. VACANCIES: CAPACITY 56",12,array('justification'=>'left'));
		$pdf->ezText('',12,array('justification'=>'left'));
		$info_male = $this->Report_model->get_count_accomodation("Male");
		$info_female = $this->Report_model->get_count_accomodation("Female");
		$male=$info_male->row();
		$female=$info_female->row();
		$db_data2[] = array('male'=>$male->accomodation_count-$male->accomodation_count,'female'=>56-$female->accomodation_count,'total'=>56-($male->accomodation_count+$female->accomodation_count));
		$col_names = array(
			'male' => 'Male',
			'female' => 'Female',
			'total' => 'Total'
		);
		$pdf->ezTable($db_data2, $col_names, '', array('width'=>200,'fontSize'=>12,'titleFontSize'=>13,'xPos'=>'left','xOrientation'=>'right'));
		$pdf->ezText('',12,array('justification'=>'left'));
		
		//classification table
		$pdf->ezText("III. CLASSIFICATION:",12,array('justification'=>'left'));
		$pdf->ezText('',12,array('justification'=>'left'));
		$count_male=0;$count_female=0;
		$classification = array("Freshman","Sophomore","Junior","Senior");
		for($i=0;$i<count($classification);$i++){
			$info_male = $this->Report_model->get_count_classification($classification[$i],"Male");
			$info_female = $this->Report_model->get_count_classification($classification[$i],"Female");
			$male=$info_male->row();
			$female=$info_female->row();
			$count_male+=$male->classification_count;
			$count_female+=$female->classification_count;
			$db_data3[] = array('year_level'=>$classification[$i],'male'=>$male->classification_count,'female'=>$female->classification_count);
		}$db_data3[] = array('year_level'=>'Total','male'=>$count_male,'female'=>$count_female);
		$col_names = array(
			'year_level' => 'Year Level',
			'male' => 'Male',
			'female' => 'Female'
		);
		$pdf->ezTable($db_data3, $col_names, '', array('width'=>200,'fontSize'=>12,'titleFontSize'=>13,'xPos'=>'left','xOrientation'=>'right'));
		$pdf->ezText('',12,array('justification'=>'left'));
		
		//regional distribution table
		$count_male=0;$count_female=0;
		$region = array("I","II","III","IVa","IVb","V","VI","VII","VIII","IX","X","XI","XII","XIII","NCR","CAR","CARAGA","ARMM");
		for($i=0;$i<count($region);$i++){
			$info_male = $this->Report_model->get_count_regional_distribution($region[$i],"Male");
			$info_female = $this->Report_model->get_count_regional_distribution($region[$i],"Female");
			$male=$info_male->row();
			$female=$info_female->row();
			$count_male+=$male->regional_count;
			$count_female+=$female->regional_count;
			$db_data4[] = array('region'=>$region[$i],'male'=>$male->regional_count,'female'=>$female->regional_count,'total'=>$male->regional_count+$female->regional_count);
		}$db_data4[] = array('region'=>'TOTAL','male'=>$count_male,'female'=>$count_female,'total'=>$count_male+$count_female);
		$col_names = array(
			'region' => 'Region',
			'male' => 'Male',
			'female' => 'Female',
			'total' => 'Total'
		);
		$pdf->ezSetY(715);
		$space="                                       ";
		$pdf->ezText("".$space.$space."IV. REGIONAL DISTRIBUTION:",12,array('justification'=>'left'));
		$pdf->ezText('',12,array('justification'=>'left'));
		$pdf->ezTable($db_data4, $col_names, '', array('width'=>200,'fontSize'=>12,'titleFontSize'=>13,'xPos'=>'520','xOrientation'=>'left'));
		$pdf->ezText('',12,array('justification'=>'left'));
		
		//college table
		$college = array("CA","CAS","CA-CAS","CDC","CEAT","CEM","CFNR","CHE","CVM");
		$total=0;
		for($i=0;$i<count($college);$i++){
			$info[] = $this->Report_model->get_count_college($college[$i]);
			$row[]=$info[$i]->row();
			$total+=$row[$i]->college_count;
		}
		$db_data5[] = array('ca'=>$row[0]->college_count,
							'cas'=>$row[1]->college_count,
							'ca-cas'=>$row[2]->college_count,
							'cdc'=>$row[3]->college_count,
							'ceat'=>$row[4]->college_count,
							'cem'=>$row[5]->college_count,
							'cfnr'=>$row[6]->college_count,
							'che'=>$row[7]->college_count,
							'cvm'=>$row[8]->college_count,
							'total'=>$total);
		$col_names = array(
			'ca' => 'CA',
			'cas' => 'CA',
			'ca-cas' => 'CA-CAS',
			'cdc' => 'CDC',
			'ceat' => 'CEAT',
			'cem' => 'CEM',
			'cfnr' => 'CFNR',
			'che' => 'CHE',
			'cvm' => 'CVM',
			'total' => 'TOTAL'
		);
		$pdf->ezText("V. COLLEGE:",12,array('justification'=>'left'));
		$pdf->ezText('',12,array('justification'=>'left'));
		$pdf->ezTable($db_data5, $col_names, '', array('width'=>470,'fontSize'=>12,'titleFontSize'=>13,'xPos'=>'left','xOrientation'=>'right'));
		$pdf->ezText('',12,array('justification'=>'left'));
		
		//footer
		$this->load->model('Admin_model');
		$query = $this->Admin_model->get_details('ACCI Dormitory');
		$row = $query->row();
		
		$pdf->ezText("\nPrepared and Submitted by:");
		$pdf->ezText("\n\n".$row->manager."");
		$pdf->ezText($row->position."");
		
		$pdf->ezSetY(233);
		$pdf->ezText("\n".$space.$space."Noted by:");
		$pdf->ezText("\n\n".$space.$space.$row->name1."");
		$pdf->ezText($space.$space.$row->position1."");
		$pdf->ezText("\n\n".$space.$space.$row->name2."");
		$pdf->ezText($space.$space.$row->position2."");
		$pdf->ezStream();}
	}
	
}

/* End of file adminPageController.php */
/* Location: ./application/controllers/adminPageController.php */
?>